import router from '@system.router';
import prompt from '@system.prompt';
const app = getApp();

export default {
    data: {
        phone: "",
        password: "",
        agree: false
    },
    onInit() {
    },
    register() {
        if (this.phone.length != 11) {
            prompt.showToast({
                message: "您输入的手机号格式不正确",
                duration: 2000
            });
            return false;
        }
        if (this.password.length < 8) {
            prompt.showToast({
                message: "您输入的密码小于8位",
                duration: 2000
            });
            return false;
        }
        if (this.agree) {
            prompt.showToast({
                message: "注册成功",
                duration: 2000
            });
            app.register(this.phone, this.password);
            setTimeout(() => router.back(), 2000);
        } else {
            prompt.showDialog({
                message: "为了更好地保障您的合法权益，请您阅读并同意以下协议《淘宝平台服务协议》《隐私权政策》《支付宝注册相关协议》",
                buttons: [
                    { text: "确定", color: "#000000" },
                ]
            })
            return false;
        }
        return true;
    },
    goBack() {
        router.back();
    },
    updatePhone(e) {
        this.phone = e.text;
    },
    updatePassword(e) {
        this.password = e.text;
    },
    toggleAgree() {
        this.agree = !this.agree;
    }
}
